package com.linkage.jz.bankruptcy.activity.Project;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.linkage.jz.bankruptcy.BankruptcyApp;
import com.linkage.jz.bankruptcy.Consts;
import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.activity.Main.CreateAddrActivity;
import com.linkage.jz.bankruptcy.activity.RegistLogin.PhoneLoginActivity;
import com.linkage.jz.bankruptcy.adapter.FullyGridLayoutManager;
import com.linkage.jz.bankruptcy.base.BaseActivity;
import com.linkage.jz.bankruptcy.base.BaseCreateActivity;
import com.linkage.jz.bankruptcy.bean.MyAddr;
import com.linkage.jz.bankruptcy.bean.MyProInfo;
import com.linkage.jz.bankruptcy.bean.TaskAtta;
import com.linkage.jz.bankruptcy.net.BaseSubscriber;
import com.linkage.jz.bankruptcy.net.Network;
import com.linkage.jz.bankruptcy.utils.FileUtil;
import com.linkage.jz.bankruptcy.utils.SPUtils;
import com.linkage.jz.bankruptcy.utils.SignUtil;
import com.linkage.jz.bankruptcy.widget.PublicNoticeDialog;
import com.linkage.jz.bankruptcy.widget.ShapeLoadingDialog;
import com.linkage.seapeak.activity.user.ImageShowActivity;
import com.linkage.seapeak.pojo.ManagersInfo;
import com.linkage.seapeak.pojo.UploadImage;
import com.linkage.seapeak.utils.ToastUtil;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.Headers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;


/**
 * A login screen that offers login via email/password.
 */
public  class EditProjectDetailActivity extends BaseCreateActivity implements OnClickListener{
    private static final String TAG = EditProjectDetailActivity.class.getSimpleName();

    private ShapeLoadingDialog shapeLoadingDialog ;
    private int addImageType = -1;

    private int num =1;
    private int tmpnum = 1;
    private String addressId;
    private ArrayList<View> editViews = new ArrayList<View>();
    private  static MyAddr mAddrInfo;
    @Override
    public void imageSizeChange(int tag, int size) {
        addImageType = tag;
    }
    @Override
    public void setListener() {
//        btn_login.setOnClickListener(this);
        top_back.setOnClickListener(this);
//        ll_phonelogin.setOnClickListener(this);
//        getPwd.setOnClickListener(this);
        top_mune1.setOnClickListener(this);
        top_mune2.setOnClickListener(this);
        im_groupadd.setOnClickListener(this);
        ll_zwr_db_addr.setOnClickListener(this);
//        im_groupadd2.setOnClickListener(this);
    }

    private EditText et_debtorName, et_projectName, et_projectLogo, et_projectNote,item_zwr_db;
    private TextView tv_projectType,item_other0,tv_projectName,tv_projectNote,item_zwr_db_addr,et_debtorName_num;
    private RelativeLayout rl_projectType,ll_zwr_db_addr;
    private List<UploadImage> mImgList = new ArrayList<>();
    private GridImagesAdapter adapter;
    private RecyclerView mRecyclerView_Logo;
    private List<UploadImage> urlList1 = new ArrayList<>();
    private List<UploadImage> urlList2 = new ArrayList<>();
    private List<UploadImage> urlList3 = new ArrayList<>();
    private List<UploadImage> urlList4 = new ArrayList<>();
    private RecyclerView recycler_court, recycler_manager, recycler_other, recycler_pass;
    private GridImagesAdapter adapter_court, adapter_manager, adapter_other, adapter_pass;
    private  String strType = "";

    private int protype;
    private static int m_addtype = 1;//1新增 2修改

    private void initviewPage3() {
        //登录层、下拉层I、其它登录方式层

        item_zwr_db = findViewById(R.id.item_zwr_db);
        item_zwr_db_addr = findViewById(R.id.item_zwr_db_addr);
        ll_zwr_db_addr = findViewById(R.id.ll_zwr_db_addr);
        recycler_court = findViewById(R.id.recycler_court);
        recycler_manager = findViewById(R.id.recycler_manager);
        recycler_other = findViewById(R.id.recycler_other);
        recycler_pass = findViewById(R.id.recycler_pass);
        et_debtorName_num = findViewById(R.id.et_debtorName_num);


    }

    @Override
    public void initData() {
        et_debtorName.setText(mInfo.getDebtorName());

        et_projectName.setText(mInfo.getProjectName());
        et_projectNote.setText(mInfo.getProjectNote());



        et_courtno.setText(mInfo.getCaseNumber());
        et_courtname.setText(mInfo.getCourtName());

        //管理人

        contacts.setText(mInfo.getContacts());
        contactsphone.setText(mInfo.getContactPhone());

        item_zwr_db.setText(mInfo.getDebtorLegalRepresentative());
//        item_zwr_db_addr.setText(mInfo.getSysAddressId());
        item_zwr_db_addr.setText(mInfo.getSysAddressName());

        if("0".equalsIgnoreCase(mInfo.getProjectType()))
        {
            strType = "破产清算";
        }else if("1".equalsIgnoreCase(mInfo.getProjectType()))
        {
            strType = "破产重整";
        }else if("2".equalsIgnoreCase(mInfo.getProjectType()))
        {
            strType = "破产和解";
        }else
        {
            strType = "其他";
        }

        if(mInfo.getManagersList().size()>0) {
            ManagersInfo managersInfo = mInfo.getManagersList().get(0);
            if("0".equalsIgnoreCase(managersInfo.getManagersType()))
            {
                ck_person.setChecked(false);
                ck_group.setChecked(true);
                group1.setVisibility(View.VISIBLE);
                person1.setVisibility(View.GONE);
                g_managersname1.setText(managersInfo.getManagersName());
                g_managersadmin.setText(managersInfo.getManagersAdministrator());
                g_managersadminphone.setText(managersInfo.getManagersAdministratorMobile());
                socialUniformCreditCode.setText(managersInfo.getSocialUniformCreditCode());

            }else{
                ck_person.setChecked(true);
                ck_group.setChecked(false);
                group1.setVisibility(View.GONE);
                person1.setVisibility(View.VISIBLE);
                p_managersname1.setText(managersInfo.getManagersName());
            }

            for(int i=1;i<mInfo.getManagersList().size();i++)
            {
                ManagersInfo newmanagersInfo = mInfo.getManagersList().get(i);
                addView(newmanagersInfo);
            }
        }

    }





    private void initWidgetPage3_4() {
        FullyGridLayoutManager manager = new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false);
        recycler_pass.setLayoutManager(manager);
        adapter_pass = new GridImagesAdapter(EditProjectDetailActivity.this, TYPE_EDIT);
        adapter_pass.setList(urlList4);
        adapter_pass.setTag(4);
//        adapter_pass.setSelectMax(9);
        recycler_pass.setAdapter(adapter_pass);
    }

    private void initWidgetPage3_3() {
        FullyGridLayoutManager manager = new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false);
        recycler_other.setLayoutManager(manager);
        adapter_other = new GridImagesAdapter(EditProjectDetailActivity.this, TYPE_EDIT);
        adapter_other.setList(urlList3);
        adapter_other.setTag(3);
//        adapter_other.setSelectMax(9);
        recycler_other.setAdapter(adapter_other);
    }

    private void initWidgetPage3_2() {
        FullyGridLayoutManager manager = new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false);
        recycler_manager.setLayoutManager(manager);
        adapter_manager = new GridImagesAdapter(EditProjectDetailActivity.this, TYPE_EDIT);
        adapter_manager.setList(urlList2);
        adapter_manager.setTag(2);
//        adapter_manager.setSelectMax(9);
        recycler_manager.setAdapter(adapter_manager);
    }
    private void initWidgetPage3_1() {
        FullyGridLayoutManager manager = new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false);
        recycler_court.setLayoutManager(manager);
        adapter_court = new GridImagesAdapter(EditProjectDetailActivity.this, TYPE_EDIT);
        adapter_court.setList(urlList1);
        adapter_court.setTag(1);
//        adapter_court.setSelectMax(9);
        recycler_court.setAdapter(adapter_court);
    }


    private void initWidgetPage1() {
        FullyGridLayoutManager manager = new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false);
        mRecyclerView_Logo.setLayoutManager(manager);
        adapter = new GridImagesAdapter(this, TYPE_EDIT,false);
        adapter.setList(mImgList);
        adapter.setSelectMax(1);
        adapter.setTag(5);
        mRecyclerView_Logo.setAdapter(adapter);
    }



     private void initviewPage1() {
        //登录层、下拉层、其它登录方式层


        top_back = findViewById(R.id.top_back);
        top_mune1 = findViewById(R.id.top_mune1);
        top_mune2 = findViewById(R.id.top_mune2);
        et_debtorName = findViewById(R.id.et_debtorName);
        et_projectName = findViewById(R.id.et_projectName);
//        et_projectLogo = findViewById(R.id.et_projectLogo);
        et_projectNote = findViewById(R.id.et_projectNote);
        tv_projectType = findViewById(R.id.tv_projectType);

         mRecyclerView_Logo = findViewById(R.id.recyclerLogo);
//        rl_addlogo = findViewById(R.id.rl_addlogo);

        item_other0 = findViewById(R.id.item_other0);
        tv_projectName = findViewById(R.id.tv_projectName);
        tv_projectNote = findViewById(R.id.tv_projectNote);
        String proType = mInfo.getProjectType();
        final String[] strTypes = {"破产清算", "破产重整", "破产和解"

                , "其他"};
        if (!"".equalsIgnoreCase(proType)) {
            protype = Integer.parseInt(proType);
            tv_projectType.setText(strTypes[protype]);

        } else {
            protype = -1;
        }

        et_debtorName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                        textView.setText(s.toString());
                et_projectName.setText(s.toString()+strType+"案");
                et_debtorName_num.setText(s.length() + "/40");
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });


        et_projectNote.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                        textView.setText(s.toString());
//                et_projectName.setText(s.toString()+strType+"案");
                tv_projectNote.setText(s.length() + "/800");

            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });

        et_projectName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                        textView.setText(s.toString());
//                et_projectName.setText(s.toString()+strType+"案");
                tv_projectName.setText(s.length() + "/60");
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });
        //    设置一个下拉的列表选择项


        rl_projectType = findViewById(R.id.rl_projectType);

        if (m_addtype == 2) {
            top_mune2.setVisibility(View.INVISIBLE);
        }
        rl_projectType.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                final List<String> values = new ArrayList<String>();

                AlertDialog.Builder builder = new AlertDialog.Builder(EditProjectDetailActivity.this);

                //builder.setIcon(R.drawable.ic_launcher);
                builder.setTitle("请选择");
                //    指定下拉列表的显示数据
                final String[] strTypes = {"破产清算", "破产重整", "破产和解"

                        , "其他"};
                //    设置一个下拉的列表选择项
                builder.setItems(strTypes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        tv_projectType.setText(strTypes[which]);

                        protype = which;
                        strType = strTypes[protype];
                        et_projectName.setText(et_debtorName.getText().toString()+strType+"案");
                        vName();
                        ChangeRed();
                        showToast("项目信息已修改");
                    }
                });
                builder.show();

            }
        });

    }

    private void ChangeRed()
    {
        if(protype == 3)
        {
            findViewById(R.id.red_1).setVisibility(View.GONE);
            findViewById(R.id.red_2).setVisibility(View.GONE);
            findViewById(R.id.red_3).setVisibility(View.GONE);
            findViewById(R.id.red_4).setVisibility(View.GONE);
            findViewById(R.id.red_5).setVisibility(View.GONE);
//            findViewById(R.id.red_6).setVisibility(View.GONE);
            findViewById(R.id.red_7).setVisibility(View.GONE);
//            findViewById(R.id.red_8).setVisibility(View.GONE);
            findViewById(R.id.red_9).setVisibility(View.GONE);
            findViewById(R.id.red_10).setVisibility(View.GONE);
            findViewById(R.id.red_11).setVisibility(View.GONE);
            for(int i=0;i<editViews.size();i++){
//                editViews.get(i);
               editViews.get(i).findViewById(R.id.red10_1).setVisibility(View.INVISIBLE);
                editViews.get(i).findViewById(R.id.red10_2).setVisibility(View.INVISIBLE);
                editViews.get(i).findViewById(R.id.red10_3).setVisibility(View.INVISIBLE);
                editViews.get(i).findViewById(R.id.red10_4).setVisibility(View.INVISIBLE);
                editViews.get(i).findViewById(R.id.red10_5).setVisibility(View.INVISIBLE);
                editViews.get(i).findViewById(R.id.red10_6).setVisibility(View.INVISIBLE);
            }

        }else{
            findViewById(R.id.red_1).setVisibility(View.VISIBLE);
            findViewById(R.id.red_2).setVisibility(View.VISIBLE);
            findViewById(R.id.red_3).setVisibility(View.VISIBLE);
            findViewById(R.id.red_4).setVisibility(View.VISIBLE);
            findViewById(R.id.red_5).setVisibility(View.VISIBLE);
//            findViewById(R.id.red_6).setVisibility(View.VISIBLE);
            findViewById(R.id.red_7).setVisibility(View.VISIBLE);
//            findViewById(R.id.red_8).setVisibility(View.VISIBLE);
            findViewById(R.id.red_9).setVisibility(View.VISIBLE);
            findViewById(R.id.red_10).setVisibility(View.VISIBLE);
            findViewById(R.id.red_11).setVisibility(View.VISIBLE);

            for(int i=0;i<editViews.size();i++) {
                editViews.get(i).findViewById(R.id.red10_1).setVisibility(View.VISIBLE);
                editViews.get(i).findViewById(R.id.red10_2).setVisibility(View.VISIBLE);
                editViews.get(i).findViewById(R.id.red10_3).setVisibility(View.VISIBLE);
                editViews.get(i).findViewById(R.id.red10_4).setVisibility(View.VISIBLE);
                editViews.get(i).findViewById(R.id.red10_5).setVisibility(View.VISIBLE);
                editViews.get(i).findViewById(R.id.red10_6).setVisibility(View.VISIBLE);
            }
        }
    }

    private  static int dialogType = 1;
    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            switch (v.getId()) {
                case R.id.ll_close:
                    noticeDialog.dismiss();
                    break;

                case R.id.btn_chancel_notice:
//                   Boolean flag =  noticelxDialog.cb_agree.isChecked();
//                    if(dialogType ==1 ) {
//                        finish();
//                    }else{
//
//                    }
                    noticeDialog.dismiss();

                    break;


                case R.id.btn_save_notice:
                    if(dialogType== 1) {
//                        mInfo.setProjectStatus("0");
//                        saveData(0);
                        noticeDialog.dismiss();
                        finish();
                    }
                    noticeDialog.dismiss();
                    break;

            }
        }
    };

//    EditText g_managersadminphone,g_managersadminphone2,g_managersadmin,g_managersadmin2,g_managersname2,g_managersname1,p_managersname1,p_managersname2;
//    EditText socialUniformCreditCode,socialUniformCreditCode2,contacts,contacts2,contactsphone,contactsphone2;
    @Override
    public void initTitle() {
        top_title = findViewById(R.id.top_title);

            top_title.setText("编辑");

//        top_mune.setVisibility(View.INVISIBLE);
    }

    @Override
    public void initView() {

    }

    ImageView mLeftLogo;
    ImageView im_groupadd;//,im_groupadd2;
    EditText et_username,et_courtno;
    TextView et_courtname;
    EditText et_password,contacts,contactsphone;
    Button btn_login;
    TextView top_title,getPwd;
    Button top_back;
    TextView top_mune1,top_mune2;
    RelativeLayout rl_courtname;
    CheckBox ck_group,ck_person;//,ck_group2,ck_person2;

    EditText g_managersadminphone,g_managersadmin,g_managersname1,p_managersname1,socialUniformCreditCode;


    LinearLayout ll_charger,ll_admin,qqlogi,group1,person1;//,ll_group2,group2,group1,person1,person2;
    private static MyProInfo mInfo;
    public static void start(Context context,MyProInfo info,int addtype) {
        Intent intent = new Intent(context, EditProjectDetailActivity.class);
        mInfo = info;

        m_addtype = addtype;
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        setContentView(R.layout.activity_create_pro_detail_edit);
        getData();
        initviewPage1();
        initviewPage2();
        initWidgetPage1();
        initviewPage3();
        initWidgetPage3_4();
        initWidgetPage3_3();
        initWidgetPage3_2();
        initWidgetPage3_1();

//        initData();

        String user = SPUtils.getInstance(Consts.SPNAME).getString("loginUser");
        String pwd = SPUtils.getInstance(Consts.SPNAME).getString("loginPwd");

//        if(!user.equalsIgnoreCase(""))
//        {
//            et_username.setText(user);
//            et_password.setText(pwd);
//        }
        shapeLoadingDialog = new ShapeLoadingDialog(this);
        super.onCreate(savedInstanceState);
    }

    private int groupnum = 1;
    private int groupper = 1;
    private int groupper2 = 1;

    //初始化视图
    private void initviewPage2() {
        //登录层、下拉层、其它登录方式层


        et_username = findViewById(R.id.et_username);
        et_password = findViewById(R.id.et_password);
        top_back = findViewById(R.id.top_back);
        top_mune1 = findViewById(R.id.top_mune1);
        top_mune2 = findViewById(R.id.top_mune2);
        getPwd = findViewById(R.id.getPwd);
        linearLayout1 = findViewById(R.id.linearLayout1);
        l = new BtnLisener();
        cl= new CheckedChangeListener();
//        ll_group2 = findViewById(R.id.ll_group2);

        et_courtno = findViewById(R.id.et_courtno);
        et_courtname = findViewById(R.id.et_courtname);
        rl_courtname = findViewById(R.id.rl_courtname);
        rl_courtname.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(EditProjectDetailActivity.this, SearchCourtActivity.class);

                startActivityForResult(intent, REQUEST_SEL_COURT_ACTIVITY);
            }
        });




        im_groupadd = findViewById(R.id.im_groupadd);

//        im_groupadd2 = findViewById(R.id.im_groupadd2);
//        ll_group2.setVisibility(View.GONE);

        ck_person = findViewById(R.id.ck_person);
//        ck_person2 = findViewById(R.id.ck_person2);
        ck_group = findViewById(R.id.ck_group);
//        ck_group2 = findViewById(R.id.ck_group2);
        person1 = findViewById(R.id.person1);
//        person2 = findViewById(R.id.person2);
        group1 = findViewById(R.id.group1);
//        group2 = findViewById(R.id.group2);

        contacts= findViewById(R.id.contacts);
        contactsphone= findViewById(R.id.contactsphone);
        g_managersadminphone = findViewById(R.id.g_managersadminphone);
        g_managersadmin = findViewById(R.id.g_managersadmin);
        g_managersname1 = findViewById(R.id.g_managersname1);
        p_managersname1 = findViewById(R.id.p_managersname1);
        socialUniformCreditCode = findViewById(R.id.socialUniformCreditCode);


//        if("".equalsIgnoreCase(mInfo.getAddRole()))
//        {
//            g_managersadmin.setFocusable(false);
//
//            g_managersadmin.setFocusableInTouchMode(false);
//
//        }else{
//            g_managersadmin.setFocusableInTouchMode(true);
//
//            g_managersadmin.setFocusable(true);
//
//        }
        g_managersadminphone.setText(BankruptcyApp.loginInfo.getLoginname());
        g_managersadminphone.setFocusable(false);
        g_managersadminphone.setFocusableInTouchMode(false);


//        contactsphone.setFocusable(false);
//        contactsphone.setFocusable(false);
        if(m_addtype == 2)
        {
            top_mune2.setVisibility(View.INVISIBLE);
        }
        et_courtname.setText(mInfo.getCourtName());
        et_courtno.setText(mInfo.getCaseNumber());
//        person1.setVisibility(View.GONE);
//        person2.setVisibility(View.GONE);
//        ArrayList<ManagersInfo> mManagerList= mInfo.getManagersList();
//        if(!"".equalsIgnoreCase(managerListStr))
//        {
//
//            try{
//                JSONArray ary  = new JSONArray(managerListStr);
//                for(int i=0;i<ary.length();i++)
//                {
//                    JSONObject object = ary.getJSONObject(i);
//                    String master = object.optString("master");
//                    String managersType = object.optString("managersType");
//                    if("true".equalsIgnoreCase(master))
//                    {
//                        if("0".equalsIgnoreCase(managersType))
//                        {
//                            ck_group.setChecked(true);
//                            ck_person.setChecked(false);
//
//
//                        }else{
////                            group1.setVisibility(View.GONE);
////                            person1.setVisibility(View.VISIBLE);
////                            ck_group.setChecked(false);
////                            ck_person.setChecked(true);
////                            p_managersname1.setText(object.optString("managersName"));
////                            contacts.setText(object.optString("contacts"));
////                            contactsphone.setText(object.optString("contactPhone"));
//                        }
//                    }else{
//                        im_groupadd.setVisibility(View.VISIBLE);
////                        ll_group2.setVisibility(View.GONE);
//                        if("0".equalsIgnoreCase(managersType))
//                        {
////                            ck_group2.setChecked(true);
////                            ck_person2.setChecked(false);
////                            group2.setVisibility(View.VISIBLE);
////                            person2.setVisibility(View.GONE);
////                            g_managersname2.setText(object.optString("managersName"));
////                            g_managersadmin2.setText(object.optString("managersAdministrator"));
////                            g_managersadminphone2.setText(object.optString("managersAdministratorMobile"));
////                            socialUniformCreditCode2.setText(object.optString("socialUniformCreditCode"));
//                        }else{
////                            ck_group2.setChecked(false);
////                            ck_person2.setChecked(true);
////                            group2.setVisibility(View.GONE);
////                            person2.setVisibility(View.VISIBLE);
////                            p_managersname2.setText(object.optString("managersName"));
////                            contacts2.setText(object.optString("contacts"));
////                            contactsphone2.setText(object.optString("contactPhone"));
//                        }
//                    }
//                }
//            }catch (Exception ex){
//                ex.printStackTrace();
//            }
//        }


        ck_person.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    ck_group.setChecked(false);
                    groupper = 1;
                    person1.setVisibility(View.VISIBLE);
                    group1.setVisibility(View.GONE);
                }else{
                    ck_group.setChecked(true);
                }
            }
        });

        ck_group.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    ck_person.setChecked(false);
                    groupper = 0;
                    group1.setVisibility(View.VISIBLE);
                    person1.setVisibility(View.GONE);
                }else{
                    ck_person.setChecked(true);
                }
            }
        });



    }

    class BtnLisener implements OnClickListener{

        @Override
        public void onClick(View v) {
            switch (v.getId()) {

                case R.id.im_groupadd2:
                    View view = (View) v.getTag();
                    removeView(view);
                    break;

                default:
                    break;
            }

        }

    }

    class CheckedChangeListener implements CompoundButton.OnCheckedChangeListener {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            View view = (View) buttonView.getTag();
            CheckBox ck_group2 =  (CheckBox)view.findViewById(R.id.ck_group2);
            CheckBox ck_person2 = (CheckBox)view.findViewById(R.id.ck_person2);
            LinearLayout group2 = (LinearLayout)view.findViewById(R.id.group2);
            LinearLayout person2 = (LinearLayout)view.findViewById(R.id.person2);
            switch (buttonView.getId()) {

                case R.id.ck_group2:


                     if(ck_group2.isChecked())
                     {
                         ck_person2.setChecked(false);
                         group2.setVisibility(View.VISIBLE);
                         person2.setVisibility(View.GONE);
                     }else{
                         ck_person2.setChecked(true);
                         person2.setVisibility(View.VISIBLE);
                         group2.setVisibility(View.GONE);
                     }
                    break;
                case R.id.ck_person2:


                    if(ck_person2.isChecked())
                    {
                        ck_group2.setChecked(false);
                        person2.setVisibility(View.VISIBLE);
                        group2.setVisibility(View.GONE);
                    }else{
                        ck_group2.setChecked(true);
                        group2.setVisibility(View.VISIBLE);
                        person2.setVisibility(View.GONE);
                    }
                    break;

                default:
                    break;
            }


        }
    }

    private void removeView(View view){
        linearLayout1.removeView(view);
        tmpnum --;
        editViews.remove(view);
    }

    public final int REQUEST_SEL_COURT_ACTIVITY = 10001;
    public final int REQUEST_CODE_ADDRESS =10002;
    String courtId = "";
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        if (resultCode == RESULT_OK) {
            if (requestCode == REQUEST_CODE_ADDRESS) {
//                addressId = intent.getStringExtra("id");
                mInfo.setSysAddressId(intent.getStringExtra("id"));
                item_zwr_db_addr.setText(intent.getStringExtra("desc"));

                mAddrInfo = (MyAddr) intent.getSerializableExtra("bean");

//                    mInfo.setAdd( new MyAddr().toArrInfo(mAddrInfo));

            }
        }

        switch (requestCode) {

            case REQUEST_SEL_COURT_ACTIVITY:
                if (resultCode == RESULT_OK) {
                    if (intent != null) {

                        String courtname = intent.getStringExtra("courtname");
                         courtId = intent.getStringExtra("courtid");
                        et_courtname.setText(courtname);

                    }
                }
                break;

        }
//        private GridImagesAdapter adapter_court, adapter_manager, adapter_other, adapter_pass;
        if (requestCode == ImageShowActivity.IMAGE_REQUEST && resultCode == Activity.RESULT_OK
                && null != intent) {
            ArrayList urlList = intent.getStringArrayListExtra("urlList");
            if (addImageType == 1) {
                urlList1.clear();
                urlList1.addAll(urlList);
                BaseCreateActivity.sorFiles(urlList1,true);
//                sorFiles(mImgList, true);
                adapter_court.notifyDataSetChanged();
            } else if (addImageType == 2) {
                urlList2.clear();
                urlList2.addAll(urlList);
                BaseCreateActivity.sorFiles(urlList2,true);
//                sorFiles(mImgList, true);
                adapter_manager.notifyDataSetChanged();
            } else if (addImageType == 3) {
                urlList3.clear();
                urlList3.addAll(urlList);
                BaseCreateActivity.sorFiles(urlList3,true);
//                sorFiles(mImgList, true);
                adapter_other.notifyDataSetChanged();
            } else if (addImageType == 4) {
                urlList4.clear();
                urlList4.addAll(urlList);
                BaseCreateActivity.sorFiles(urlList4,true);
//                sorFiles(mImgList, true);
                adapter_pass.notifyDataSetChanged();
            }else if(addImageType ==5)
            {
//                ArrayList urlList = data.getStringArrayListExtra("urlList");
                mImgList.clear();
                mImgList.addAll(urlList);
                BaseCreateActivity.sorFiles(mImgList,true);
//                sorFiles(mImgList, true);
                adapter.notifyDataSetChanged();
            }
        }
    }


    @Override
    public void onClick(View view) {

            String phone = "";
            String code = "";
            String pwd = "";
            switch (view.getId()) {
                case R.id.ll_zwr_db_addr:
                    Intent intent = new Intent(this, CreateAddrActivity.class);
                    if (mAddrInfo != null) {
//                        MyAddr addr = new MyAddr();
//                        addr =  new MyAddr().toMyArr(mIn确认录入申报信息fo.getAdd());
                        intent.putExtra(CreateAddrActivity.KEY_BEAN, mAddrInfo);
                    }
                    intent.putExtra(CreateAddrActivity.KEY_FROM,CreateAddrActivity.FROM_FLOW);
                    startActivityForResult(intent, REQUEST_CODE_ADDRESS);
                    break;
                case R.id.btn_login:
                    //返回
//                MainActivity.start(this);
//                finish();
                    phone = et_username.getText().toString();
//                    code = et_vcode.getText().toString();
                    pwd = et_password.getText().toString();
                    if ("".equalsIgnoreCase(phone)) {
                        Toast.makeText(this, "手机号码不能为空", Toast.LENGTH_SHORT).show();
                        return;
                    }
                    if ("".equalsIgnoreCase(pwd)) {
                        Toast.makeText(this, "密码不能为空", Toast.LENGTH_SHORT).show();
                        return;
                    }
//                    LoginUser(phone, code, pwd);
                    break;
                case R.id.ll_phonelogin:
                    PhoneLoginActivity.start(this);
                    finish();
                    break;
                case R.id.top_back:
                    dialogType =1;
                    noticeDialog = new PublicNoticeDialog(EditProjectDetailActivity.this,onClickListener,
                            1, "提示", "放弃编辑？",
                            "否","是");
                    noticeDialog.show();
                    break;
                case R.id.top_mune2:
                    saveData(2);
                    break;
                case R.id.top_mune1:


                    saveData(2);
                    break;
                case R.id.im_groupadd:

//                    groupnum = 2;
//                    im_groupadd.setVisibility(View.INVISIBLE);
//                    ll_group2.setVisibility(View.VISIBLE);
                    addView();
                    break;
                case R.id.im_groupadd2:
                    groupnum = 1;
                    im_groupadd.setVisibility(View.VISIBLE);
//                    ll_group2.setVisibility(View.GONE);
                    break;
                default:
                    break;
            }


    }
    private OnClickListener l;
    private CheckedChangeListener cl;
    private LinearLayout linearLayout1;


    private void addView(ManagersInfo newmanagersInfo){
        View view = LayoutInflater.from(getBaseContext()).inflate(R.layout.activity_create_pro_detail_two_item, null);
        ImageView btnDel = (ImageView) view.findViewById(R.id.im_groupadd2);
        CheckBox ck_group2=(CheckBox)view.findViewById(R.id.ck_group2);
        CheckBox ck_person2=(CheckBox)view.findViewById(R.id.ck_person2);

        if("3".equalsIgnoreCase(mInfo.getProjectType())) {
            view.findViewById(R.id.red10_1).setVisibility(View.INVISIBLE);
            view.findViewById(R.id.red10_2).setVisibility(View.INVISIBLE);
            view.findViewById(R.id.red10_3).setVisibility(View.INVISIBLE);
            view.findViewById(R.id.red10_4).setVisibility(View.INVISIBLE);
            view.findViewById(R.id.red10_5).setVisibility(View.INVISIBLE);
            view.findViewById(R.id.red10_6).setVisibility(View.INVISIBLE);
        }else{
            view.findViewById(R.id.red10_1).setVisibility(View.VISIBLE);
            view.findViewById(R.id.red10_2).setVisibility(View.VISIBLE);
            view.findViewById(R.id.red10_3).setVisibility(View.VISIBLE);
            view.findViewById(R.id.red10_4).setVisibility(View.VISIBLE);
            view.findViewById(R.id.red10_5).setVisibility(View.VISIBLE);
            view.findViewById(R.id.red10_6).setVisibility(View.VISIBLE);
        }

        LinearLayout group2 = (LinearLayout)view.findViewById(R.id.group2);
        LinearLayout person2 = (LinearLayout)view.findViewById(R.id.person2);

        EditText g_managersname2 = (EditText)view.findViewById(R.id.g_managersname2);
        EditText g_managersadmin2 = (EditText)view.findViewById(R.id.g_managersadmin2);
        EditText g_managersadminphone2 = (EditText)view.findViewById(R.id.g_managersadminphone2);
        EditText socialUniformCreditCode2 = (EditText)view.findViewById(R.id.socialUniformCreditCode2);

        EditText p_managersname2 = (EditText)view.findViewById(R.id.p_managersname2);


        TextView tv_grouptitle2 = (TextView)view.findViewById(R.id.tv_grouptitle2);
        if(tmpnum == 1)
        {
            num =1;
        }
        num++;
        tmpnum++;
        tv_grouptitle2.setText("管理人");

        if("0".equalsIgnoreCase(newmanagersInfo.getManagersType()))
        {
            ck_person2.setChecked(false);
            ck_group2.setChecked(true);
            group2.setVisibility(View.VISIBLE);
            person2.setVisibility(View.GONE);
            g_managersname2.setText(newmanagersInfo.getManagersName());
            g_managersadmin2.setText(newmanagersInfo.getManagersAdministrator());
            g_managersadminphone2.setText(newmanagersInfo.getManagersAdministratorMobile());
            g_managersadminphone2.setEnabled(false);
            socialUniformCreditCode2.setText(newmanagersInfo.getSocialUniformCreditCode());

        }else{
            ck_person2.setChecked(true);
            ck_group2.setChecked(false);
            group2.setVisibility(View.GONE);
            person2.setVisibility(View.VISIBLE);
            person2.setEnabled(false);
            p_managersname2.setText(newmanagersInfo.getManagersName());
        }


        btnDel.setTag(view);
        btnDel.setOnClickListener(l);
        ck_group2.setOnCheckedChangeListener(cl);
        ck_group2.setTag(view);
        ck_person2.setOnCheckedChangeListener(cl);
        ck_person2.setTag(view);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        linearLayout1.addView(view, params);

        editViews.add(view);
    }

    private void addView(){
        View view = LayoutInflater.from(getBaseContext()).inflate(R.layout.activity_create_pro_detail_two_item, null);
        ImageView btnDel = (ImageView) view.findViewById(R.id.im_groupadd2);
        CheckBox ck_group2=(CheckBox)view.findViewById(R.id.ck_group2);
        CheckBox ck_person2=(CheckBox)view.findViewById(R.id.ck_person2);

        if(protype == 3) {
            view.findViewById(R.id.red10_1).setVisibility(View.INVISIBLE);
            view.findViewById(R.id.red10_2).setVisibility(View.INVISIBLE);
            view.findViewById(R.id.red10_3).setVisibility(View.INVISIBLE);
            view.findViewById(R.id.red10_4).setVisibility(View.INVISIBLE);
            view.findViewById(R.id.red10_5).setVisibility(View.INVISIBLE);
            view.findViewById(R.id.red10_6).setVisibility(View.INVISIBLE);
        }else{
            view.findViewById(R.id.red10_1).setVisibility(View.VISIBLE);
            view.findViewById(R.id.red10_2).setVisibility(View.VISIBLE);
            view.findViewById(R.id.red10_3).setVisibility(View.VISIBLE);
            view.findViewById(R.id.red10_4).setVisibility(View.VISIBLE);
            view.findViewById(R.id.red10_5).setVisibility(View.VISIBLE);
            view.findViewById(R.id.red10_6).setVisibility(View.VISIBLE);
        }


        EditText g_managersname2 = (EditText)view.findViewById(R.id.g_managersname2);
        EditText g_managersadmin2 = (EditText)view.findViewById(R.id.g_managersadmin2);
        EditText g_managersadminphone2 = (EditText)view.findViewById(R.id.g_managersadminphone2);
        EditText socialUniformCreditCode2 = (EditText)view.findViewById(R.id.socialUniformCreditCode2);

        EditText p_managersname2 = (EditText)view.findViewById(R.id.p_managersname2);


        TextView tv_grouptitle2 = (TextView)view.findViewById(R.id.tv_grouptitle2);
        if(tmpnum == 1)
        {
            num =1;
        }
        num++;
        tmpnum++;
        tv_grouptitle2.setText("管理人");

        btnDel.setTag(view);
        btnDel.setOnClickListener(l);
        ck_group2.setOnCheckedChangeListener(cl);
        ck_group2.setTag(view);
        ck_person2.setOnCheckedChangeListener(cl);
        ck_person2.setTag(view);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        linearLayout1.addView(view, params);

        editViews.add(view);
        changeName();
    }

    public void changeName()
    {
        for(int i=0;i<editViews.size();i++)
        {

        }
    }
    public void saveData(int m_type)
    {

        if(BankruptcyApp.tokeninfo == null|| BankruptcyApp.tokeninfo.getToken() == null)
        {
            getToken();
            return;
        }

        OkHttpClient okHttpClient = new OkHttpClient();
        HashMap<String, String> params = new HashMap<String, String>();
        Random random = new Random();
        String rom = random.nextLong()+"";
        String timestamp =System.currentTimeMillis()+"";

        String str_debtorName = et_debtorName.getText().toString();
        if ("".equalsIgnoreCase(str_debtorName)) {
            showToast("债务人名称不能为空", com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
//            Toast.makeText(this, "债务人名称不能为空", Toast.LENGTH_SHORT).show();
            return;
        }


        mInfo.setDebtorName(str_debtorName);
        String str_projectName = et_projectName.getText().toString();
        if ("".equalsIgnoreCase(str_projectName)) {
            showToast("项目名称不能为空", com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
//            Toast.makeText(this, "项目名称不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        if (protype == -1) {
            showToast("请选择项目类型", com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
//            Toast.makeText(this, "请选择项目类型", Toast.LENGTH_SHORT).show();
            return;
        }
       
        mInfo.setProjectName(str_projectName);
//        String str_projectLogo  = et_projectLogo.getText().toString();

        String str_projectLogo =  "";
        if(mImgList.size()>0)
        {
            str_projectLogo = mImgList.get(0).getFilepath();
        }
        mInfo.setProjectLogo(str_projectLogo);

        String str_projectNote = et_projectNote.getText().toString();
        mInfo.setProjectNote(str_projectNote);


//        mInfo.setProjectStatus(m_type+"");
        mInfo.setProjectType(protype + "");
//        mInfo.setPublicSection("0,1");


        String str_courtName  = et_courtname.getText().toString();
        if ("".equalsIgnoreCase(str_courtName)&& !"3".equalsIgnoreCase(mInfo.getProjectType())) {
            showToast("法院名称不能为空", com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
//            Toast.makeText(this, "法院名称不能为空", Toast.LENGTH_SHORT).show();
            return;
        }
        mInfo.setCourtName(str_courtName);
        mInfo.setCourtId(courtId);
        String str_courtno  = et_courtno.getText().toString();
        if ("".equalsIgnoreCase(str_courtno)&& !"3".equalsIgnoreCase(mInfo.getProjectType())) {
            showToast("法院案件编号不能为空", com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
//            Toast.makeText(this, "法院案件编号不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        mInfo.setCaseNumber(str_courtno);

        contacts = findViewById(R.id.contacts);
        contactsphone = findViewById(R.id.contactsphone);



        JSONArray ary = new JSONArray();

        try {

            if (ck_group.isChecked()) {
                String str_g_managersname1 = g_managersname1.getText().toString();
                if ("".equalsIgnoreCase(str_g_managersname1)&& !"3".equalsIgnoreCase(mInfo.getProjectType())) {
                    showToast("管理人名称不能为空", com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
//                    Toast.makeText(this, "管理人名称不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }
                String str_g_managersadmin = g_managersadmin.getText().toString();
                if ("".equalsIgnoreCase(str_g_managersadmin)&& !"3".equalsIgnoreCase(mInfo.getProjectType())) {
                    showToast("管理人负责人不能为空", com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
                    Toast.makeText(this, "管理人负责人不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }

                String str_g_managersadminphone = g_managersadminphone.getText().toString();
                if ("".equalsIgnoreCase(str_g_managersadminphone)&& !"3".equalsIgnoreCase(mInfo.getProjectType())) {
                    showToast("管理人负责人手机不能为空", com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
//                    Toast.makeText(this, "管理人负责人手机不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }
                String str_socialUniformCreditCode = socialUniformCreditCode.getText().toString();
//                if ("".equalsIgnoreCase(str_socialUniformCreditCode)&& !"3".equalsIgnoreCase(mInfo.getProjectType())) {
//                    Toast.makeText(this, "社会信用代码不能为空", Toast.LENGTH_SHORT).show();
//                    return;
//                }

                JSONObject obj = new JSONObject();
                obj.put("managersType", "0");
                obj.put("managersName", str_g_managersname1);
                obj.put("managersAdministrator", str_g_managersadmin);
                obj.put("managersAdministratorMobile", str_g_managersadminphone);
                obj.put("socialUniformCreditCode", str_socialUniformCreditCode);
                obj.put("master", "true");
                ary.put(obj);
            }

            if (ck_person.isChecked()) {

                String str_g_managersname1 = p_managersname1.getText().toString();
                if ("".equalsIgnoreCase(str_g_managersname1)&& !"3".equalsIgnoreCase(mInfo.getProjectType())) {
                    showToast("管理人名称不能为空", com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
//                    Toast.makeText(this, "管理人名称不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }



                JSONObject obj = new JSONObject();
                obj.put("managersType", "1");
                obj.put("managersName", str_g_managersname1);
                obj.put("master", "true");
                ary.put(obj);
            }

            for(int i=0;i<editViews.size();i++){
                CheckBox ck_group2=(CheckBox)editViews.get(i).findViewById(R.id.ck_group2);
                CheckBox ck_person2=(CheckBox)editViews.get(i).findViewById(R.id.ck_person2);

                EditText g_managersname2 = (EditText)editViews.get(i).findViewById(R.id.g_managersname2);
                EditText g_managersadmin2 = (EditText)editViews.get(i).findViewById(R.id.g_managersadmin2);
                EditText g_managersadminphone2 = (EditText)editViews.get(i).findViewById(R.id.g_managersadminphone2);
                EditText socialUniformCreditCode2 = (EditText)editViews.get(i).findViewById(R.id.socialUniformCreditCode2);
                EditText p_managersname2 = (EditText)editViews.get(i).findViewById(R.id.p_managersname2);
                TextView tv_grouptitle2 = (TextView)editViews.get(i).findViewById(R.id.tv_grouptitle2);



                if (ck_group2.isChecked()) {
                    String str_g_managersname2 = g_managersname2.getText().toString();
                    if ("".equalsIgnoreCase(str_g_managersname2)) {
                        String str  = tv_grouptitle2.getText().toString() +  "名称不能为空";
                        showToast(str, com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
//                        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
                        return;
                    }
                    String str_g_managersadmin2 = g_managersadmin2.getText().toString();
//                    if ("".equalsIgnoreCase(str_g_managersadmin2)) {
//                        String str  = tv_grouptitle2.getText().toString() +  "负责人不能为空";
//                        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
//                        return;
//                    }

                    String str_g_managersadminphone2 = g_managersadminphone2.getText().toString();
//                    if ("".equalsIgnoreCase(str_g_managersadminphone2)) {
//                        String str  = tv_grouptitle2.getText().toString() +  "负责人手机不能为空";
//                        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
//                        return;
//                    }
                    String str_socialUniformCreditCode2 = socialUniformCreditCode2.getText().toString();
//                    if ("".equalsIgnoreCase(str_socialUniformCreditCode2)) {
//                        String str  = tv_grouptitle2.getText().toString() +  "社会信用代码不能为空";
//                        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
//                        return;
//                    }

                    JSONObject obj = new JSONObject();
                    obj.put("managersType", "0");
                    obj.put("managersName", str_g_managersname2);
                    obj.put("managersAdministrator", str_g_managersadmin2);
                    obj.put("managersAdministratorMobile", str_g_managersadminphone2);
                    obj.put("socialUniformCreditCode", str_socialUniformCreditCode2);
                    obj.put("master", "false");
                    ary.put(obj);
                }

                if (ck_person2.isChecked()) {

                    String str_g_managersname2 = p_managersname2.getText().toString();
                    if ("".equalsIgnoreCase(str_g_managersname2)) {
                        String str  = tv_grouptitle2.getText().toString() +  "名称不能为空";
//                        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
                        showToast(str, com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
                        return;
                    }

                    JSONObject obj = new JSONObject();
                    obj.put("managersType", "1");
                    obj.put("managersName", str_g_managersname2);
                    obj.put("master", "false");
                    ary.put(obj);
                }
            }

        }catch (Exception ex)
        {
            ex.printStackTrace();
        }


        if ("".equalsIgnoreCase(contacts.getText().toString().trim())&& !"3".equalsIgnoreCase(mInfo.getProjectType())) {
            showToast("联系人姓名不能为空", com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
//            Toast.makeText(this, "联系人姓名不能为空", Toast.LENGTH_SHORT).show();
            return;
        }
        mInfo.setContacts(contacts.getText().toString().trim());

        if ("".equalsIgnoreCase(contactsphone.getText().toString().trim())&& !"3".equalsIgnoreCase(mInfo.getProjectType())) {
            showToast("联系手机号不能为空", com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
//            Toast.makeText(this, "联系人姓名不能为空", Toast.LENGTH_SHORT).show();
            return;
        }
        mInfo.setContactPhone(contactsphone.getText().toString().trim());
        JSONArray jsonArray = new JSONArray();
        JSONArray jsonArray2 = new JSONArray();
        JSONArray jsonArray3 = new JSONArray();
        JSONArray jsonArray4 = new JSONArray();

        try {
//            for (int i = 0; i < urlList1.size(); i++) {
//                JSONObject jsonObject = new JSONObject();
////                jsonObject.put("attachmentName", urlList1.get(i).getFilename());
//                jsonObject.putOpt("attachmentName", "相关附件"+(i+1)+".jpg");
//                jsonObject.put("attachmentDownloadAddress", urlList1.get(i).getFilepath());
//                jsonObject.put("attachmentSize", urlList1.get(i).getFilesize());
//                jsonArray.put(jsonObject);
//            }
            for (int i = 0; i < urlList1.size(); i++) {
                if (TextUtils.equals(urlList1.get(i).getFilename(), NAME_ADD)) {
                    continue;
                }
                JSONObject obj = new JSONObject();
                try {
                    if (FileUtil.isImage(urlList1.get(i).getFilename())) {
                        obj.putOpt("attachmentName", "相关附件" + (i + 1) + ".jpg");
                    } else {
                        obj.putOpt("attachmentName", urlList1.get(i).getFilename());
                    }
                    obj.putOpt("attachmentDownloadAddress", urlList1.get(i).getFilepath());
                    obj.putOpt("attachmentSize", urlList1.get(i).getFilesize());
                    obj.putOpt("loadUrl", urlList1.get(i).getLoadUrl());
                    jsonArray.put(obj);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

//            for (int i = 0; i < urlList2.size(); i++) {
//                JSONObject jsonObject = new JSONObject();
////                jsonObject.put("attachmentName", urlList2.get(i).getFilename());
//                jsonObject.putOpt("attachmentName", "相关附件"+(i+1)+".jpg");
//                jsonObject.put("attachmentDownloadAddress", urlList2.get(i).getFilepath());
//                jsonObject.put("attachmentSize", urlList2.get(i).getFilesize());
//                jsonArray2.put(jsonObject);
//            }
            for (int i = 0; i < urlList2.size(); i++) {
                if (TextUtils.equals(urlList2.get(i).getFilename(), NAME_ADD)) {
                    continue;
                }
                JSONObject obj = new JSONObject();
                try {
                    if (FileUtil.isImage(urlList2.get(i).getFilename())) {
                        obj.putOpt("attachmentName", "相关附件" + (i + 1) + ".jpg");
                    } else {
                        obj.putOpt("attachmentName", urlList2.get(i).getFilename());
                    }
                    obj.putOpt("attachmentDownloadAddress", urlList2.get(i).getFilepath());
                    obj.putOpt("attachmentSize", urlList2.get(i).getFilesize());
                    obj.putOpt("loadUrl", urlList2.get(i).getLoadUrl());
                    jsonArray2.put(obj);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }


//            for (int i = 0; i < urlList3.size(); i++) {
//                JSONObject jsonObject = new JSONObject();
////                jsonObject.put("attachmentName", urlList3.get(i).getFilename());
//                jsonObject.putOpt("attachmentName", "相关附件"+(i+1)+".jpg");
//                jsonObject.put("attachmentDownloadAddress", urlList3.get(i).getFilepath());
//                jsonObject.put("attachmentSize", urlList3.get(i).getFilesize());
//                jsonArray3.put(jsonObject);
//            }
            for (int i = 0; i < urlList3.size(); i++) {
                if (TextUtils.equals(urlList3.get(i).getFilename(), NAME_ADD)) {
                    continue;
                }
                JSONObject obj = new JSONObject();
                try {
                    if (FileUtil.isImage(urlList3.get(i).getFilename())) {
                        obj.putOpt("attachmentName", "相关附件" + (i + 1) + ".jpg");
                    } else {
                        obj.putOpt("attachmentName", urlList3.get(i).getFilename());
                    }
                    obj.putOpt("attachmentDownloadAddress", urlList3.get(i).getFilepath());
                    obj.putOpt("attachmentSize", urlList3.get(i).getFilesize());
                    obj.putOpt("loadUrl", urlList3.get(i).getLoadUrl());
                    jsonArray3.put(obj);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }


//            for (int i = 0; i < urlList4.size(); i++) {
//                JSONObject jsonObject = new JSONObject();
////                jsonObject.put("attachmentName", urlList4.get(i).getFilename());
//                jsonObject.putOpt("attachmentName", "相关附件"+(i+1)+".jpg");
//                jsonObject.put("attachmentDownloadAddress", urlList4.get(i).getFilepath());
//                jsonObject.put("attachmentSize", urlList4.get(i).getFilesize());
//                jsonArray4.put(jsonObject);
//            }
            for (int i = 0; i < urlList4.size(); i++) {
                if (TextUtils.equals(urlList4.get(i).getFilename(), NAME_ADD)) {
                    continue;
                }
                JSONObject obj = new JSONObject();
                try {
                    if (FileUtil.isImage(urlList4.get(i).getFilename())) {
                        obj.putOpt("attachmentName", "相关附件" + (i + 1) + ".jpg");
                    } else {
                        obj.putOpt("attachmentName", urlList4.get(i).getFilename());
                    }
                    obj.putOpt("attachmentDownloadAddress", urlList4.get(i).getFilepath());
                    obj.putOpt("attachmentSize", urlList4.get(i).getFilesize());
                    obj.putOpt("loadUrl", urlList4.get(i).getLoadUrl());
                    jsonArray4.put(obj);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        String strTmp1 = jsonArray.toString();
        String strTmp2 = jsonArray2.toString();
        String strTmp3 = jsonArray3.toString();
        String strTmp4 = jsonArray4.toString();

        mInfo.setDebtorYyzzFileListStr(strTmp4);
        mInfo.setCourtSlwsFileListStr(strTmp1);
        mInfo.setCourtManagerFileListStr(strTmp2);
        mInfo.setOtherFileListStr(strTmp3);

        mInfo.setDebtorLegalRepresentative( item_zwr_db.getText().toString().trim());
//        mInfo.setSysAddressId(item_zwr_db_addr.getText().toString().trim());



        shapeLoadingDialog.setLoadingText("提交信息中...");
        shapeLoadingDialog.setCanceledOnTouchOutside(false);
        shapeLoadingDialog.show();
        mInfo.setProjectStatus(m_type+"");
//        mInfo.setPublicSection("0,1");

        String json = ary.toString();
        mInfo.setManagerListStr(json);

        String sign = SignUtil.createSign(Consts.APPKEY,params);
        String userToken = SPUtils.getInstance(Consts.SPNAME).getString("userToken","");

        RequestBody requestBody = new FormBody.Builder()
                .add("appid","1000000001")
                .add("nonce",rom)
                .add("timestamp", timestamp)
                .add("token", BankruptcyApp.tokeninfo.getToken())
                .add("userToken", userToken)
//                .add("appVersion", "0.0.1")

                .add("addRole", mInfo.getAddRole())
                .add("id", mInfo.getId())
                .add("debtorName", mInfo.getDebtorName())
                .add("projectType",  mInfo.getProjectType())
                .add("projectName",  mInfo.getProjectName())
                .add("projectLogo",  mInfo.getProjectLogo())
                .add("projectNote",  mInfo.getProjectNote())
                .add("courtName",  mInfo.getCourtName())
                .add("courtId",  mInfo.getCourtId())
                .add("caseNumber",  mInfo.getCaseNumber())
                .add("projectStatus",mInfo.getProjectStatus())
                .add("debtorLegalRepresentative",  mInfo.getDebtorLegalRepresentative())
                .add("sysAddressId",  mInfo.getSysAddressId())
                .add("publicStatus", "1")
                .add("publicSection",  mInfo.getPublicSection())
                .add("close",  mInfo.getClose())
                .add("allowJoin",  mInfo.getAllowJoin())
                .add("closeClaimFiling",  mInfo.getCloseClaimFiling())
                .add("openDiscussion",  mInfo.getOpenDiscussion())
                .add("allowCreditorsChangInfo",  mInfo.getAllowCreditorsChangInfo())
                .add("displayedInstantly",  mInfo.getDisplayedInstantly())
                .add("creditorsVisibleDetails",  mInfo.getCreditorsVisibleDetails())
                .add("openAdministratorList",  mInfo.getOpenAdministratorList())

                .add("openAdministratorInfo",  mInfo.getOpenAdministratorInfo())
                .add("openCreditorsList",  mInfo.getOpenCreditorsList())
                .add("openCreditorsInfo",  mInfo.getOpenCreditorsInfo())

                .add("managerListStr",  mInfo.getManagerListStr())
                .add("debtorYyzzFileListStr",  mInfo.getDebtorYyzzFileListStr())
                .add("courtSlwsFileListStr",  mInfo.getCourtSlwsFileListStr())
                .add("courtManagerFileListStr",  mInfo.getCourtManagerFileListStr())
                .add("otherFileListStr",  mInfo.getOtherFileListStr())
                .add("contacts",mInfo.getContacts())
                .add("contactPhone",mInfo.getContactPhone())



                .build();

        String url = Consts.WEBURL_ADDPRO;
        if(!"".equalsIgnoreCase(mInfo.getId()))
        {
            url = Consts.WEBURL_UPDATEPRO;
        }
        Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .build();

        okHttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
//                Log.d(TAG, "onFailure: " + e.getMessage());
                shapeLoadingDialog.dismiss();
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
//                Log.d(TAG, response.protocol() + " " +response.code() + " " + response.message());
                Headers headers = response.headers();


                shapeLoadingDialog.dismiss();
                String str = response.body().string();
                try{
                    JSONObject object = new JSONObject(str);
                    if(object.optInt("code") == 0)
                    {

                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                EventBus.getDefault().post(mInfo);
                                //更新UI
//                                Toast.makeText(EditProjectDetailActivity.this,
//                                        "提交成功",Toast.LENGTH_SHORT).show();
                                showToast("项目信息已修改", ToastUtil.TOAST_TYPE.SUCCESS);
                                finish();

                            }

                        });
                    }else{
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                //更新UI
                                Toast.makeText(EditProjectDetailActivity.this,
                                        "提交失败",Toast.LENGTH_SHORT).show();


                            }

                        });
                    }

                    str = "";
                }catch (Exception ex)
                {

                    ex.printStackTrace();
                }
            }
        });


    }
    private PublicNoticeDialog noticeDialog;
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {


        if (keyCode == KeyEvent.KEYCODE_BACK) {
//            exit();
//            return false;
            dialogType =1;
            noticeDialog = new PublicNoticeDialog(EditProjectDetailActivity.this,onClickListener,
                    1, "提示", "放弃编辑？",
                    "否","是");
            noticeDialog.show();
        }
        return super.onKeyDown(keyCode, event);
    }

//    private OnClickListener onClickListener = new OnClickListener() {
//        @Override
//        public void onClick(View v) {
//
//            switch (v.getId()) {
//                case R.id.ll_close:
//                    noticeDialog.dismiss();
//                    break;
//
//                case R.id.btn_chancel_notice:
////                   Boolean flag =  noticelxDialog.cb_agree.isChecked();
//                    if(dialogType ==1 ) {
//                        finish();
//                    }else{
//
//                    }
//                    noticeDialog.dismiss();
//
//                    break;
//
//                case R.id.btn_save_notice:
//                    if(dialogType== 1) {
//                        saveData(1);
//                    }
//                    noticeDialog.dismiss();
//                    break;
//
//            }
//        }
//    };

    private void vName() {


//        mShapeLoadingDialog.setLoadingText("提交信息中...");
//        mShapeLoadingDialog.setCanceledOnTouchOutside(false);
//        mShapeLoadingDialog.show();
        String str_projectName = et_projectName.getText().toString();
        if ("".equalsIgnoreCase(str_projectName)) {
            Toast.makeText(this, "项目名称不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        Observable<JsonObject> observable;

        observable = Network
                .getAPIService()
                .vName( str_projectName);


        observable
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscriber<JsonObject>() {
                    @Override
                    public void onNext(JsonObject json) {

                        int code = json.get("code").getAsInt();
                        if (code != 0) {
                            super.onNext(json);
                            return;
                        }
                        JsonObject objdata = json.getAsJsonObject("data");
                        Boolean flag = objdata.get("returnFlag").getAsBoolean();
                        if (flag)
                        {
                            dialogType =2;
                            noticeDialog = new PublicNoticeDialog(EditProjectDetailActivity.this,onClickListener,
                                    5,"系统已有重名项目！","如您是法院指定的项目管理人，请继续创建，" +
                                    "\n" +
                                    "如有疑问可联系平台客服处理。",
                                    "否","继续创建");
                            noticeDialog.show();
                        }

                    }

                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                    }

                    @Override
                    public void onError(Throwable e) {
                        mShapeLoadingDialog.dismiss();
                        super.onError(e);
                    }
                });

    }


    public void getData() {
        String userToken = SPUtils.getInstance(Consts.SPNAME).getString("userToken", "");
        Network
                .getAPIService()
                .getProjectDetailInfo(userToken, mInfo.getId())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscriber<JsonObject>() {
                    @Override
                    public void onNext(JsonObject json) {
                        int code = json.get("code").getAsInt();
                        if (code != 0) {
                            super.onNext(json);
                            return;
                        }
                        JsonObject data = json.getAsJsonObject("data");

                        String projectLogoShowUrl ="";

                        JsonObject projectInfo = data.get("projectInfo").getAsJsonObject();
                        String logo ="";

                        try {
                            projectLogoShowUrl = data.get("projectLogoShowUrl").getAsString();
                            logo =  projectInfo.get("projectLogo").getAsString();
                        }catch (Exception ex)
                        {
                            ex.printStackTrace();
                        }

                        mImgList.clear();
//        for (int i = 0; i < mInfo.getDebtorYyzzFileListStrList().size(); i++) {
//            TaskAtta atta = mInfo.getDebtorYyzzFileListStrList().get(i);
                        if(!"".equalsIgnoreCase(mInfo.getProjectLogo())) {
                            JSONObject obj6 = new JSONObject();
                            try {
                                obj6.putOpt("filename", "logo.png");
                                obj6.putOpt("filepath", logo);
                                obj6.putOpt("filesize", "11");
                                obj6.putOpt("loadUrl", projectLogoShowUrl);
                                mImgList.add(new Gson().fromJson(obj6.toString(), UploadImage.class));
                                BaseCreateActivity.sorFiles(mImgList, true);
//                                sorFiles(mImgList, true);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }


                        //债务人营业执照附件集合
                        JsonArray arr1 = data.getAsJsonArray("attachmentYYZZList");
                        List<TaskAtta>  list  = TaskAtta.parse(arr1);
                        urlList4.clear();
                        for (int i = 0; i < list.size(); i++) {
                            TaskAtta atta = list.get(i);
                            JSONObject obj = new JSONObject();
                            try {
                                obj.putOpt("filename", atta.getAttachmentName());
                                obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                                obj.putOpt("filesize", atta.getAttachmentSize());
                                obj.putOpt("loadUrl", atta.getAttachmentWatermarkAddress());
                                urlList4.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                                BaseCreateActivity.sorFiles(urlList4, true);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                        mInfo.setDebtorYyzzFileListStrList(TaskAtta.parse(arr1));
//                        initData();


//        mInfo.getCourtSlwsFileList().addAll(TaskAtta.parse(arr1));
//        mInfo.getCourtManagerFileList().addAll(TaskAtta.parse(arr2));
//        mInfo.getOtherFileList().addAll(TaskAtta.parse(arr3));

                        //债务人营业执照
//                        urlList4.clear();
//                        JsonArray arr2 = data.getAsJsonArray("courtSlwsFileList");
//                        List<TaskAtta>  list2  = TaskAtta.parse(arr2);
//                        for (int i = 0; i < list2.size(); i++) {
//                            TaskAtta atta = list2.get(i);
//                            JSONObject obj = new JSONObject();
//                            try {
//                                obj.putOpt("filename", atta.getAttachmentName());
//                                obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
//                                obj.putOpt("filesize", atta.getAttachmentSize());
//                                obj.putOpt("loadUrl", atta.getAttachmentWatermarkAddress());
//                                urlList4.add(new Gson().fromJson(obj.toString(), UploadImage.class));
//                            } catch (JSONException e) {
//                                e.printStackTrace();
//                            }
//                        }

                        //法院受理文书
                        urlList1.clear();
                        JsonArray arr5 = data.getAsJsonArray("attachmentSLWSList");
                        List<TaskAtta>  list5  = TaskAtta.parse(arr5);
                        for (int i = 0; i < list5.size(); i++) {
                            TaskAtta atta = list5.get(i);
                            JSONObject obj1 = new JSONObject();
                            try {
                                obj1.putOpt("filename", atta.getAttachmentName());
                                obj1.putOpt("filepath", atta.getAttachmentDownloadAddress());
                                obj1.putOpt("filesize", atta.getAttachmentSize());
                                obj1.putOpt("loadUrl", atta.getAttachmentWatermarkAddress());
                                urlList1.add(new Gson().fromJson(obj1.toString(), UploadImage.class));
                                BaseCreateActivity.sorFiles(urlList1, true);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                        mInfo.setCourtSlwsFileList(TaskAtta.parse(arr5));

                        //法院指定管理人文书
                        urlList2.clear();
                        JsonArray arr2 = data.getAsJsonArray("attachmentGLSWSList");
                        List<TaskAtta>  list2  = TaskAtta.parse(arr2);
                        for (int i = 0; i < list2.size(); i++) {
                            TaskAtta atta = list2.get(i);
                            JSONObject obj2 = new JSONObject();
                            try {
                                obj2.putOpt("filename", atta.getAttachmentName());
                                obj2.putOpt("filepath", atta.getAttachmentDownloadAddress());
                                obj2.putOpt("filesize", atta.getAttachmentSize());
                                obj2.putOpt("loadUrl", atta.getAttachmentWatermarkAddress());
                                urlList2.add(new Gson().fromJson(obj2.toString(), UploadImage.class));
                                BaseCreateActivity.sorFiles(urlList2, true);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                        mInfo.setCourtManagerFileList(TaskAtta.parse(arr2));

                        //其他文件
                        urlList3.clear();
                        JsonArray arr3 = data.getAsJsonArray("attachmentOtherList");
                        List<TaskAtta>  list3  = TaskAtta.parse(arr3);
                        for (int i = 0; i < list3.size(); i++) {
                            TaskAtta atta = list3.get(i);
                            JSONObject obj3 = new JSONObject();
                            try {
                                obj3.putOpt("filename", atta.getAttachmentName());
                                obj3.putOpt("filepath", atta.getAttachmentDownloadAddress());
                                obj3.putOpt("filesize", atta.getAttachmentSize());
                                obj3.putOpt("loadUrl", atta.getAttachmentWatermarkAddress());
                                urlList3.add(new Gson().fromJson(obj3.toString(), UploadImage.class));
                                BaseCreateActivity.sorFiles(urlList3, true);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                        mInfo.setCourtManagerFileList(TaskAtta.parse(arr3));

                         MyAddr sysAddressInfo = new Gson().fromJson(data.getAsJsonObject("projectInfo").get("addressInfo").toString(), MyAddr.class);
                        mAddrInfo = sysAddressInfo;
                        if(sysAddressInfo!=null) {
                            item_zwr_db_addr.setText(sysAddressInfo.getFullAddress());
                        }
//                        adapter_court, adapter_manager, adapter_other, adapter_pass;

                        adapter.notifyDataSetChanged();
                        adapter_court.notifyDataSetChanged();
                        adapter_manager.notifyDataSetChanged();
                        adapter_other.notifyDataSetChanged();
                        adapter_pass.notifyDataSetChanged();
//
                        ChangeRed();
//                        initWidgetPage3_4();

//                        mAdapter.notifyDataSetChanged();
                    }

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                    }
                });
    }

}

